package com.zang.blogz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zang.blogz.dto.ArticleHomeDTO;
import com.zang.blogz.entity.Article;
import com.zang.blogz.model.output.ArticleTopVO;
import com.zang.blogz.model.output.WebsiteConfigVO;
import com.zang.blogz.result.Result;
import com.zang.blogz.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * 游客可查看
 *
 * @author 臧臧 on 2022/6/17
 */
@RestController
@RequestMapping("/blogz/visitors")
@Api(tags = "首页模块")
public class VisitorsViewTheController {

    @Autowired
    private ArticleService articleService;

    @Autowired
    private WebsiteConfigService websiteConfigService;

    @GetMapping("/index/article")
    @ApiOperation(value = "获取首页文章列表", notes = "获取首页文章列表")
    public Result<IPage<ArticleHomeDTO>> getIndexArticleInfo(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) throws ExecutionException, InterruptedException {

        return Result.ok(articleService.getIndexArticleInfo(pageNo, pageSize));
    }

    @GetMapping("/index/topArticle")
    @ApiOperation(value = "获取置顶文章列表", notes = "获取置顶文章列表")
    public Result<List<ArticleTopVO>> getTopArticle(){

        return Result.ok(articleService.getTopArticle());
    }

    @GetMapping("/index/userinfo")
    @ApiOperation(value = "获取首页用户信息", notes = "获取首页用户信息")
    public Result<WebsiteConfigVO> getIndexUserInfo() {

        return Result.ok(websiteConfigService.getUserInfo());

    }



}